* @throws MWException
* @return string
*/
- public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = null ) {
+ public function sprintfDate( $format, $ts, DateTimeZone $zone = null, &$ttl = 'unused' ) {
$s = '';
$raw = false;
$roman = false;
}
}
- if ( $usedSecond ) {
+ if ( $ttl === 'unused' ) {
+ // No need to calculate the TTL, the caller wont use it anyway.
+ } elseif ( $usedSecond ) {
$ttl = 1;
} elseif ( $usedMinute ) {
$ttl = 60 - substr( $ts, 12, 2 );
);
}
+ /**
+ * sprintfDate should only calculate a TTL if the caller is going to use it.
+ * @covers Language::sprintfDate
+ */
+ public function testSprintfDateNoTtlIfNotNeeded() {
+ $noTtl = 'unused'; // Value used to represent that the caller didn't pass a variable in.
+ $ttl = null;
+ $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $noTtl );
+ $this->getLang()->sprintfDate( 'YmdHis', wfTimestampNow(), null, $ttl );
+
+ $this->assertSame(
+ 'unused',
+ $noTtl,
+ 'If the caller does not set the $ttl variable, do not compute it.'
+ );
+ $this->assertInternalType( 'int', $ttl, 'TTL should have been computed.' );
+ }
+
public static function provideSprintfDateSamples() {
return [
[